package demo1;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public int maxArea(int[] height) {
        int l = 0;
        int r = height.length-1;
        int max = 0;
        while (l < r) {
            int sum = Math.min(height[l],height[r]) * (r-l);
            max = Math.max(max,sum);
            if(height[l]>=height[r]){
                r--;
            }else{
                l++;
            }
        }
        return max;
    }

    public int numJewelsInStones(String jewels, String stones) {
        HashMap<Character,Integer> map = new HashMap<>();
        int count = 0;
        for (int i = 0; i < jewels.length(); i++) {
            map.put(jewels.charAt(i),0);
        }
        for (int i = 0; i < stones.length(); i++) {
            if(map.containsKey(stones.charAt(i))){
                count++;
            }
        }
        return count;
    }

    public Node copyRandomList(Node head) {
        HashMap<Node,Node> map = new HashMap<>();
        Node pcur = head;
        while (pcur != null) {
            Node newnode = new Node(pcur.val);
            //newnode.val = pcur.val;
            map.put(pcur,newnode);
            pcur = pcur.next;
        }
        pcur = head;

        while (pcur != null) {
            map.get(pcur).next = map.get(pcur.next);
            map.get(pcur).random = map.get(pcur.random);
            pcur = pcur.next;
        }
        return map.get(head);
    }
}
